package 滑动窗口;

import java.util.HashSet;
import java.util.Set;

/**
 * @author tmh
 * @date 2024/11/25 20:47
 * @description
 */
public class T3无重复字符的最长子串 {
    public int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int maxLen =0;
        int left=0,right=0;
        for (int i =0;i<s.toCharArray().length;i++) {
            while (set.contains(s.charAt(i))){
                //这里移除的是字符，不是下标
                set.remove(s.charAt(left));
                left++;
            }
            set.add(s.charAt(i));
            int len = right-left+1;
            maxLen=Math.max(len,maxLen);
            right++;
        }
        return maxLen;
    }
}
